<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2018/8/16
 * Time: 17:00
 */

namespace app\admin\model;


use think\Model;

class MechanismMien extends Model
{
    /**
     * 获取当前机构下的风采列表
     * @param $mechanism_id
     * @param $page
     * @param $limit
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function meinLists($mechanism_id, $page, $limit){
        $lists = $this->alias('mm')
            ->where('mm.mechanism_id', $mechanism_id)
            ->join('up_mechanism um', 'um.mechanism_id = mm.mechanism_id', 'left')
            ->field('mm.mien_id, mm.mien_url, mm.mien_description, um.mechanism_type')
            ->order('mm.mien_id desc')
            ->page($page, $limit)
            ->select();
        return $lists;
    }
    
    /**
     * 获取条件搜索的记录总数，用于分页
     * @param $where  搜索条件
     * @return int|string
     */
    public function getCount($mechanism_id){
        $count = $this->where('mechanism_id', $mechanism_id)->count();
        return $count;
    }
    
    /**
     * 添加风采
     * @param $data
     * @return false|int
     */
    public function insertMien($data){
        $res = $this->allowField(true)->save($data);
        return $res;
    }
    
    /**
     * 获取单条风采
     * @param $mien_id
     * @return array|false|\PDOStatement|string|Model
     */
    public function getOneMien($mien_id){
        $info = $this->where('mien_id', $mien_id)->find();
        return $info;
    }
    
    /**
     * 修改风采
     * @param $mien_id
     * @param $data
     * @return $this
     */
    public function updataMien($mien_id, $data){
        $res = $this->where('mien_id', $mien_id)->update($data);
        return $res;
    }
}